﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using LINQtoLDAPDemo_Model;

namespace LINQtoLDAPDemo_WPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private MainWindowViewModel vm;

        public MainWindow()
        {
            InitializeComponent();

            vm = new MainWindowViewModel();
            this.DataContext = vm;
        }

        /* I had originally planned to change these event methods to RelayCommands
         * but upon reading this post about limiting the view model's ties to control events-- I think I will wait on that
         * http://stackoverflow.com/questions/2963830/passing-event-args-and-sender-to-the-relaycommand
         */
        private void cboGroups_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            vm.ReloadViewData((Group)cboGroups.SelectedItem);
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            vm.AddUsersToGroup((Group)cboGroups.SelectedItem, lbNonMembers.SelectedItems.Cast<User>().ToArray());
        }

        private void btnRemove_Click(object sender, RoutedEventArgs e)
        {
            vm.RemoveUsersFromGroup((Group)cboGroups.SelectedItem, lbMembers.SelectedItems.Cast<User>().ToArray());
        }
    }
}
